﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BG.Web.Admin.Article.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%--<%@ Register Src="../UserControls/Editor.ascx" TagName="Editor" TagPrefix="uc1" %>--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <script type="text/javascript" src="../Kwan.Base.js"></script>
    <script type="text/javascript" src="Kwan.Article.js"></script>
    <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="Article" />

        <ext:Store runat="server" ID="ClassDS">
            <Reader>
                <ext:JsonReader IDProperty="EntityID">
                    <Fields>
                        <ext:RecordField Name="EntityID" />
                        <ext:RecordField Name="NameCN" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>

        <ext:Store ID="Store1" runat="server" OnRefreshData="RefreshDS" AutoDecode="false" RemoteSort="True">
            <Proxy>
                <ext:PageProxy />
            </Proxy>
            <Reader>
                <ext:JsonReader IDProperty="EntityID">
                    <Fields>
                        <ext:RecordField Name="EntityID" />
						<ext:RecordField Name="Cid" />
                        <ext:RecordField Name="ClassName" />
						<ext:RecordField Name="Click" />
						<ext:RecordField Name="CreatedDate" />
						<ext:RecordField Name="Hot" />
						<ext:RecordField Name="Image" />
						<ext:RecordField Name="English" />
						<ext:RecordField Name="Keyword" />
						<ext:RecordField Name="Enable" />
						<ext:RecordField Name="Sort" />
						<ext:RecordField Name="Source" />
						<ext:RecordField Name="Title" />                    
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <AutoLoadParams>
                <ext:Parameter Name="start" Value="0" Mode="Raw" />
                <ext:Parameter Name="limit" Value="15" Mode="Raw"/>
            </AutoLoadParams>
            <SortInfo Field="EntityID" Direction="DESC" />
            <Listeners> 
                <LoadException Handler="Ext.MessageBox.alert('系统提示', response.statusText);" />                            
            </Listeners>
        </ext:Store>
        <ext:Viewport runat="server" Layout="Column">
        <Items>
        <ext:Panel ID="Panel1" ColumnWidth=".2" runat="server" Icon="ApplicationTileVertical">
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="BtnAddClassInfo" runat="server" Text="添加父类别" Icon="Add" ToolTip="子类别可右键以下某项添加">
                            <Listeners>
                                <Click Handler="Article.InitClassInfo('0');" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        <ext:Button ID="Button1" runat="server" Text="刷新" IconCls="x-tbar-loading">
                            <Listeners>
                                <Click Handler="Article.RefreshTree();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:Menu ID="TreeContextMenu" runat="server" EnableScrolling="false">
                    <Items>
                        <ext:MenuItem ID="AppendChild" runat="server" Text="添加子类别" Icon="Add" />
                        <ext:MenuSeparator />
                        <ext:MenuItem ID="Rename" runat="server" Text="修改" Icon="Pencil" />
                        <ext:MenuItem ID="Remove" runat="server" Text="删除" Icon="Delete" />
                    </Items>
                    <Listeners>
                        <ItemClick Handler="Kwan.updateTree(#{ClassTree},menuItem.id);" />
                    </Listeners>
                </ext:Menu>
                <ext:TreePanel ID="ClassTree" AutoScroll="true" Animate="true" EnableDD="true" ContainerScroll="true" AutoHeight="true" Border="false" Header="false" RootVisible="false" Mode="Remote" runat="server" OnRemoteRename="RemoteRename" OnRemoteRemove="RemoteRemove" OnRemoteAppend="RemoteAppend" OnRemoteMove="RemoteMove">
                    <Root>
                        <ext:AsyncTreeNode Text="Examples" NodeID="root" Expanded="true" Checked="False" />
                    </Root>
                    <Loader>
                        <ext:PageTreeLoader RequestMethod="POST" OnNodeLoad="GetExamplesNodes" PreloadChildren="True" />
                    </Loader>
                    <SelectionSubmitConfig Encode="true" />
                    <Listeners>
                        <ContextMenu Fn="Kwan.showMenu" StopEvent="true" />
                        <Click Handler="#{txtFilter}.setValue(node.id);" />
                        <%--<Render Handler="this.getRootNode().expand(true);" Delay="50" />--%>
                    </Listeners>
                </ext:TreePanel>
            </Items>
        </ext:Panel>
        <ext:Panel runat="server" Layout="Fit" ColumnWidth=".8"><Items>
        <ext:GridPanel ID="GridPanel1" TrackMouseOver="true" StripeRows="true" runat="server" StoreID="Store1" ColumnLines="True" AutoExpandColumn="Title" Header="False" Frame="true" Height="500">
            <ColumnModel runat="server">
			    <Columns>
                    <ext:RowNumbererColumn />
					<ext:Column Header="标题" DataIndex="Title" Width="80" />
					<ext:Column Header="子类别" DataIndex="ClassName" Width="80" />
					<ext:Column Header="点击" DataIndex="Click" Width="80" />
					<ext:Column Header="关键词" DataIndex="Keyword" Width="80" />
                    <ext:CommandColumn Header="推荐" DataIndex="Hot" Width="40">
                        <Commands>
                            <ext:GridCommand CommandName="Hot" />
                        </Commands>
                        <PrepareToolbar Fn="Kwan.prepareBit" />
                    </ext:CommandColumn>
                    <ext:CommandColumn Header="显示" DataIndex="Enable" Width="40">
                        <Commands>
                            <ext:GridCommand CommandName="Enable" />
                        </Commands>
                        <PrepareToolbar Fn="Kwan.prepareBit" />
                    </ext:CommandColumn>
					<ext:DateColumn Header="创建日期" DataIndex="CreatedDate" Width="80" />
			    </Columns>
            </ColumnModel>
            <TopBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Hidden ID="txtFilter" runat="server" AutoDataBind="true">
                            <Listeners>
                                <Change Handler="Store1.reload();" Delay="30" />
                            </Listeners>
                        </ext:Hidden>
                        <ext:TriggerField ID="txtSearch" runat="server" EmptyText=" 全文搜索.." EnableKeyEvents="true">
                            <Listeners>
                                <KeyDown Handler="if(!Ext.isEmpty(this.getValue())) { this.triggers[0].show();}else{this.triggers[0].hide();}" />
                                <TriggerClick Handler="if (index == 1) { Store1.reload(); } if(index == 0) { #{txtSearch}.reset(); this.triggers[0].hide(); }" />
                            </Listeners>
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" Qtip="清空" />
                                <ext:FieldTrigger Icon="Search" Qtip="搜索"/>
                            </Triggers>
                        </ext:TriggerField>
                        <ext:ToolbarFill runat="server" />
                        <ext:Button ID="BtnAddInfo" runat="server" Text="添加" Icon="Add">
                            <DirectEvents>
                                <Click OnEvent="BtnAddInfo_Click" />
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="BtnDeleteInfo" runat="server" Text="批量删除" Icon="Delete">
                            <Listeners>
                                <Click Handler="Kwan.CheckDelete(#{GridPanel1}.getRowsValues({selectedOnly:true}));" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarSeparator runat="server" />
                        <ext:Button runat="server" Text="推荐" Icon="ArrowSwitchBlueGreen">
                            <Menu>
                                <ext:Menu ID="MenuChangeHot" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="Hot_1" runat="server" Text="推荐" Icon="BulletTick" />
                                        <ext:MenuItem ID="Hot_0" runat="server" Text="不推荐" Icon="BulletCross" />
                                    </Items>
                                    <Listeners>
                                        <ItemClick Handler="Article.ChangeState(Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true})),menuItem.id);" />
                                    </Listeners>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                        <ext:Button ID="BtnChangeEnable" runat="server" Text="显示" Icon="ArrowSwitchBlueGreen">
                            <Menu>
                                <ext:Menu ID="Menu1" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="Enable_1" runat="server" Text="显示" Icon="BulletTick" />
                                        <ext:MenuItem ID="Enable_0" runat="server" Text="不显示" Icon="BulletCross" />
                                    </Items>
                                    <Listeners>
                                        <ItemClick Handler="Article.ChangeState(Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true})),menuItem.id);" />
                                    </Listeners>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <SelectionModel>
               <ext:CheckboxSelectionModel runat="server" />                   
            </SelectionModel>
            <LoadMask ShowMask="true" />
            <SaveMask ShowMask="true" />
            <BottomBar>
                <ext:PagingToolbar runat="server" PageSize="15">
                    <Items>
                        <ext:Label runat="server" Text="每页显示:" />
                        <ext:ToolbarSpacer runat="server" Width="10" />
                        <ext:ComboBox Editable="false" runat="server" Width="80">
                            <Items>
                                <ext:ListItem Text="15" />
                                <ext:ListItem Text="20" />
                                <ext:ListItem Text="50" />
                                <ext:ListItem Text="100" />
                            </Items>
                            <SelectedItem Value="15" />
                            <Listeners>
                                <Select Handler="#{PagingToolBar1}.pageSize = parseInt(this.getValue()); #{PagingToolBar1}.doLoad();" />
                            </Listeners>
                        </ext:ComboBox>
                    </Items>
                </ext:PagingToolbar>
            </BottomBar>
            <Listeners>
                <Command Handler="Kwan.CellCommand(this, record, command, rowIndex)" />
                <RowDblClick Handler="Kwan.CellCommand(this, this.store.getAt(rowIndex), 'Edit', rowIndex)" />
            </Listeners>        
        </ext:GridPanel>
        </Items></ext:Panel>
        </Items>
        </ext:Viewport>
        <ext:Window ID="EditWindow" runat="server" Icon="Group" Title="编辑数据" Width="650" Height="400" AutoShow="false" Modal="true" Collapsible="true" Maximizable="true" Hidden="true" Layout="Fit" LabelWidth="70" AnimateTarget="GridPanel1">
            <Items>
                <ext:TabPanel ID="TabPanel1" runat="server" Border="false" DeferredRender="false">
                    <Items>
                        <ext:FormPanel ID="ArticleForm" MonitorValid="true" runat="server" Title="基本内容" Icon="ChartOrganisation" Padding="5" Layout="Form" LabelAlign="Right" LabelWidth="70" MonitorResize="true">
                            <Items>
                                <ext:Hidden ID="txtID" runat="server" />
								<ext:TextField ID="txtTitle" FieldLabel="标题" AnchorHorizontal="98%" AllowBlank="false" runat="server" />
                                <ext:DropDownField ID="txtCid" runat="server" FieldLabel="类别" Editable="false" Width="300" TriggerIcon="Search" Mode="ValueText" >
                                    <Component>
                                        <ext:TreePanel ID="EWTree" runat="server" Icon="Accept" Height="300" AutoScroll="true" RootVisible="false">
                                        <Root>
                                            <ext:AsyncTreeNode Text="Examples" NodeID="root" Expanded="true" Checked="False" />
                                        </Root>
                                        <Loader>
                                            <ext:PageTreeLoader RequestMethod="POST" OnNodeLoad="GetExamplesNodes" PreloadChildren="true" />
                                        </Loader>

                                        <SelectionSubmitConfig Encode="true" />
                                        <Listeners>
                                            <Click Handler="this.dropDownField.setValue(node.id,node.attributes.text,true);" />
                                        </Listeners>
                                    </ext:TreePanel>
                                    </Component>
                                    <Listeners>
                                        <Expand Handler="this.component.getRootNode().expand(true);" Single="true" Delay="10" />
                                    </Listeners>
                                </ext:DropDownField>
								<ext:TextField ID="txtKeyword" FieldLabel="关键词" AnchorHorizontal="98%" runat="server" />
								<ext:TextField ID="txtSort" FieldLabel="排序" AnchorHorizontal="98%" runat="server" />
								<ext:TextField ID="txtSource" FieldLabel="来源" AnchorHorizontal="98%" runat="server" />
                                <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" ColumnsNumber="3" FieldLabel="选项" AnchorHorizontal="50%">
                                    <Items>
                                        <ext:Checkbox ID="txtHot" BoxLabel="推荐" runat="server" />
                                        <ext:Checkbox ID="txtEnable" BoxLabel="显示" runat="server" />
                                        <ext:Checkbox ID="txtEnglish" BoxLabel="英文" runat="server" />
                                    </Items>
                                </ext:CheckboxGroup> 
								<ext:DateField ID="txtCreatedDate" FieldLabel="创建日期" AnchorHorizontal="30%" runat="server" Editable="False" Disabled="True" />
                            </Items>
                            <Listeners>
                                <ClientValidation Handler="#{SaveButton}.setDisabled(!valid);" />
                            </Listeners>
                        </ext:FormPanel>
                        <ext:FormPanel ID="FormPanel1" MonitorValid="true" runat="server" Title="详细内容" Icon="ChartOrganisation" Padding="5" Layout="Fit" LabelAlign="Right" LabelWidth="70" MonitorResize="true">
                            <Items>
                                <ext:HtmlEditor ID="txtContent" runat="server">
                                    <Listeners>
                                        <Render Handler="Kwan.htmlEditorRender(this);" />
                                    </Listeners>
                                </ext:HtmlEditor>
                            </Items>
                        </ext:FormPanel>
                    </Items>
                </ext:TabPanel>
            </Items>
            <Buttons>
                <ext:Button ID="SaveButton" runat="server" Text="保存" Icon="Disk">
                    <DirectEvents>
                        <Click OnEvent="SaveEditWindow" Failure="Ext.MessageBox.alert('系统提示', response.statusText);">
                            <EventMask Target="CustomTarget" CustomTarget="={#{EditWindow}.body}" ShowMask="True" />
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="CancelButton" runat="server" Text="返回" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{EditWindow}.hide();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Window>
        <%--类别窗口--%>
        <ext:Window ID="ClassWindow" runat="server" Icon="Group" Title="编辑数据" Width="400" Height="200" AutoShow="false" Modal="true" Collapsible="true" Maximizable="true" Hidden="true" Layout="column" LabelWidth="70" AnimateTarget="GridPanel1">
        <Items>
            <ext:FormPanel ColumnWidth=".6" ID="ClassForm" MonitorValid="true" runat="server"  Icon="ChartOrganisation" Padding="5" Layout="Form" LabelAlign="Right" LabelWidth="70" MonitorResize="true">
                <Items>
                    <ext:Hidden ID="txtClassID" runat="server" />
			        <ext:TextField ID="txtClassNameCN" FieldLabel="中文名称" AnchorHorizontal="98%" AllowBlank="false" runat="server" />
			        <ext:TextField ID="txtClassNameEN" FieldLabel="英文名称" AnchorHorizontal="98%" runat="server" />
                    <ext:ComboBox ID="txtClassPid" Editable="false" StoreID="ClassDS" FieldLabel="类别" DisplayField="NameCN" ValueField="EntityID" EmptyText="请选择..." AnchorHorizontal="60%" runat="server" Hidden="true">
                        <Template Visible="False" EnableViewState="False"></Template>
                    </ext:ComboBox>
			        <ext:TextField ID="txtClassSort" FieldLabel="排序" AnchorHorizontal="98%" runat="server" />
                </Items>
                <Listeners>
                    <ClientValidation Handler="#{ClassSaveButton}.setDisabled(!valid);" />
                </Listeners>
                <Buttons>
                    <ext:Button ID="ClassSaveButton" runat="server" Text="保存" Icon="Disk">
                        <DirectEvents>
                            <Click OnEvent="SaveClassForm" Failure="Ext.MessageBox.alert('系统提示', response.statusText);">
                                <EventMask Target="CustomTarget" CustomTarget="={#{ClassWindow}.body}" ShowMask="True" />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button ID="BtnClassCancel" runat="server" Text="返回" Icon="Cancel">
                        <Listeners>
                            <Click Handler="#{ClassWindow}.hide(null);" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </Items>
        </ext:Window>

        <ext:Window ID="winUploadNews" runat="server" Hidden="true" Title="插入图片" Width="270" Height="120" Layout="Fit">
            <Items>
                <ext:FormPanel ID="fpUpload" runat="server" Layout="Form" MonitorValid="true" Padding="5" LabelAlign="Right" LabelWidth="60">
                    <Items>
                        <ext:FileUploadField ID="txtFileUpload" AnchorHorizontal="90%" FieldLabel="选择图片" runat="server" ButtonText=" 选择.." AllowBlank="false" />
                    </Items>
                    <Buttons>
                        <ext:Button ID="btnUpload" runat="server" Text="上传" Icon="Disk">
                            <Listeners>
                                <Click Handler="Kwan.uploadNews('txtContent');" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="btnCancel" runat="server" Text="返回" Icon="Cancel">
                            <Listeners>
                                <Click Handler="#{winUploadNews}.hide();" />
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                    <Listeners>
                        <ClientValidation Handler="#{btnUpload}.setDisabled(!valid);" />
                    </Listeners>
                </ext:FormPanel>
            </Items>
        </ext:Window>
    </form>
</body>
</html>